package com.example.park_management.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.park_management.entity.Constructionproject_kzx;
import com.example.park_management.service.IConstructionprojectService_kzx;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 泽西
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/constructionprojects")
public class ConstructionprojectController_kzx {


        @Resource
        private IConstructionprojectService_kzx constructionprojectService;

        //新增或更新
        @PostMapping
        public Boolean save(@RequestBody Constructionproject_kzx constructionprojectKzx) {
                 return constructionprojectService.saveConstructionproject(constructionprojectKzx);
        }

        @DeleteMapping("/{projectID}")
        public Boolean delete(@PathVariable Integer projectID) {
                return constructionprojectService.removeById(projectID);
        }

        @GetMapping("/")
        public List<Constructionproject_kzx> findAll() {
                return constructionprojectService.list();
        }

        @GetMapping("/{projectID}")
        public Constructionproject_kzx findOne(@PathVariable Integer projectID) {
                return constructionprojectService.getById(projectID);
                }

        //分页查询 用mybatis-plus的方式查询
        @GetMapping("/page")
        public Page <Constructionproject_kzx> findPage(@RequestParam Integer pageNum,
                                                       @RequestParam Integer pageSize,
                                                       @RequestParam(defaultValue = "") String projectName,
                                                       @RequestParam(defaultValue = "") String constructionLocation) {

                QueryWrapper<Constructionproject_kzx> queryWrapper = new QueryWrapper<>();
                if(!"".equals(projectName)){
                        queryWrapper.like("projectName",projectName);
                }
                if(!"".equals(constructionLocation)){
                        queryWrapper.like("constructionLocation",constructionLocation);
                }
                queryWrapper.orderByDesc("projectID");
                return constructionprojectService.page(new Page<>(pageNum, pageSize),queryWrapper);
        }




        }

